#include<reg51.h>

sbit LE_Char = P2^0;
sbit LE_Pos = P2^1;

unsigned char num[] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xd8, 0x80, 0x90, 0x88, 0x83, 0xc6, 0xa1, 0x86, 0x8e};

unsigned char string[16] = {"0123456789ABCDEF"};

unsigned char position[8] = {0x80, 0x40, 0x20,  0x10, 0x08, 0x04, 0x02, 0x01};

void delay(unsigned int a)
{
    while(a--);
}

void main()
{
    unsigned char i, j;
    unsigned char length = 16, temp;
    while(1)
    {
        for ( j = 0; j < 100; j++)
        {
            for ( i = 0; i < 8; i++)
            {
                P0 = position[i];
                LE_Pos = 1;
                LE_Pos = 0;
                temp = string[i] - 48;
                if (temp>=17)
                {
                    temp -= 7;
                }
                P0 = num[temp];
                LE_Char = 1;
                LE_Char = 0;
                delay(100);
            }
            
        }
        temp = string[0];
        for ( i = 0; i < length-1; i++)
        {
            string[i] = string[i+1];
        }
        string[length-1] = temp;
    }
}